package ua.kharkiv.knure.karimov.Task2;

public class Vector<E> {
	private Object[] massiv = new Object[0];

	int count = 0;

	public Vector() {

	}

	public int add(E add) {
		Object[] contain1 = new Object[count + 1];
		for (int i = 0; i < count; i++)
			contain1[i] = massiv[i];
		contain1[count] = add;
		massiv = contain1;

		return ++count;
	}

	public int delete(int j) {
		Object[] contain1 = new Object[count - 1];
		int t = 0;
		for (int i = 0; i < count; i++) {
			if (j == i) {
				t++;
				continue;
			}
			contain1[i + t] = massiv[i];
		}
		massiv = contain1;

		return --count;
	}

	public int count() {
		return massiv.length;
	}

	public E index(int i) {
		return (E) massiv[i];
	}

	public void clear() {
		massiv=new Object[0];
		count=0;
	}

	public String print() {
		StringBuilder s = new StringBuilder();
		for (int i = 0; i < massiv.length; i++){ 
				s.append(massiv[i].toString() + "\n");
		}
		return s.toString();
	}
}
